<template>
  <div>
      <input type="text" class="content" v-model="title" @keyup.enter="add" placeholder="请输入你的任务名称，按回车键确认">
  </div>
</template>

<script>
import {nanoid} from 'nanoid'
export default {
  name: "Header",
  data(){
    return{
      title:''
    }
  },
  props:['addTodo'],
  methods:{
    add(){
      //校验数据
      if(!this.title.trim()) return alert("输入的值不得为空");
      //将用户输入包装成一个todo对象
      const addObj={id:nanoid(),title:this.title,done:false};
      //通知App组件去添加一个todo对象
      this.addTodo(addObj)
      //清空输入
      this.title=''
    }
  }
}
</script>

<style scoped lang="less">
div{
  width: 90%;
  height: 8%;
  background-color: #ffffff;
  box-shadow: 1px 1px 5px 1px rgba(0,0,0,0.1),-1px -1px 5px 1px rgba(0,0,0,0.1);
  margin: 10px auto 2px auto;
  display: flex;
  .content{
    width: 95%;
    height: 80%;
    font-size: 25px;
    outline: none;
    display: block;
    margin: auto;
    justify-content: center;
    align-self: center;
    border: none;
  }
}
</style>
